﻿using Lis.IBLL;
using Lis.Model;
using Lis.Repository;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Lis.Common;

namespace Lis.BLL
{
    public class BookInfoService : BaseService<BookInfo>, IBookInfoService
    {
        #region 01，根据题名查询图书信息+ServiceResult<IEnumerable<object>> GetEntityByName(string name)
        /// <summary>
        /// 根据题名查询图书信息
        /// </summary>
        /// <param name="name">题名</param>
        /// <returns></returns>
        public ServiceResult<IEnumerable<object>> GetEntityByName(string name)
        {
            if (!string.IsNullOrEmpty(name))
            {
                if (name.CheckStr())
                {
                    return new ServiceResult<IEnumerable<object>>()
                    {
                        Success = true,
                        Result = ((BookInfoRepository)DBSession.SysBookInfoRepository).GetEntitiesByName(name),
                        Message = "",
                        Code = "10000"
                    };
                }
                else
                {
                    return new ServiceResult<IEnumerable<object>>()
                    {
                        Success = false,
                        Result = null,
                        Message = "请输入正确的书名进行查询",
                        Code = "10002"
                    };
                }
            }
            else
            {
                return new ServiceResult<IEnumerable<object>>()
                {
                    Success = false,
                    Result = null,
                    Message = "请输入正确的书名进行查询",
                    Code = "10001"
                };
            }
        } 
        #endregion

        #region 02，根据ISBN查询图书信息+ServiceResult<IEnumerable<object>> GetEntityByISBN(string isbn)
        /// <summary>
        /// 根据ISBN查询图书信息
        /// </summary>
        /// <param name="isbn">isbn号</param>
        /// <returns></returns>
        public ServiceResult<IEnumerable<object>> GetEntityByISBN(string isbn)
        {
            if (!string.IsNullOrEmpty(isbn))
            {
                if (isbn.NotcheckStr())
                {
                    isbn = isbn.Replace("-", "");
                    return new ServiceResult<IEnumerable<object>>()
                    {
                        Success = true,
                        Result = ((BookInfoRepository)DBSession.SysBookInfoRepository).GetEntityByISBN(isbn),
                        Message = "",
                        Code = "10000"
                    };
                }
                else
                {
                    return new ServiceResult<IEnumerable<object>>()
                    {
                        Success = false,
                        Result = null,
                        Message = "请输入正确的ISBN号进行查询",
                        Code = "10002"
                    };
                }
            }
            else
            {
                return new ServiceResult<IEnumerable<object>>()
                {
                    Success = false,
                    Result = null,
                    Message = "请输入正确的ISBN号进行查询",
                    Code = "10001"
                };
            }
        } 
        #endregion

        #region 03，根据作者查询信息+ServiceResult<IEnumerable<object>> GetEntityByAuthor(string author)
        /// <summary>
        /// 根据作者查询信息
        /// </summary>
        /// <param name="author">作者</param>
        /// <returns></returns>
        public ServiceResult<IEnumerable<object>> GetEntityByAuthor(string author)
        {
            if (!String.IsNullOrEmpty(author))
            {
                if (author.CheckStr())
                {
                    return new ServiceResult<IEnumerable<object>>()
                    {
                        Success = true,
                        Result = ((BookInfoRepository)DBSession.SysBookInfoRepository).GetEntitiesByAuthor(author),
                        Message = "",
                        Code = "10000"
                    };
                }
                else
                {
                    return new ServiceResult<IEnumerable<object>>()
                    {
                        Success = false,
                        Result = null,
                        Message = "请输入正确的作者进行查询",
                        Code = "10002"
                    };
                }
            }
            else
            {
                return new ServiceResult<IEnumerable<object>>()
                {
                    Success = false,
                    Result = null,
                    Message = "请输入正确的作者进行查询",
                    Code = "10001"
                };
            }
        } 
        #endregion

        #region 04，根据出版社查询信息+ServiceResult<IEnumerable<object>> GetEntityByPulish(string publish)
        /// <summary>
        /// 根据出版社查询信息
        /// </summary>
        /// <param name="publish">出版社</param>
        /// <returns></returns>
        public ServiceResult<IEnumerable<object>> GetEntityByPulish(string publish)
        {
            if (!string.IsNullOrEmpty(publish))
            {
                if (publish.CheckStr())
                {
                    return new ServiceResult<IEnumerable<object>>()
                    {
                        Success = true,
                        Result = ((BookInfoRepository)DBSession.SysBookInfoRepository).GetEntitiesByPublish(publish),
                        Message = "",
                        Code = "10000"
                    };
                }
                else
                {
                    return new ServiceResult<IEnumerable<object>>()
                    {
                        Success = false,
                        Result = null,
                        Message = "请输入正确的出版社进行查询",
                        Code = "10002"
                    };
                }
            }
            else
            {
                return new ServiceResult<IEnumerable<object>>()
                {
                    Success = false,
                    Result = null,
                    Message = "请输入正确的出版社进行查询",
                    Code = "10001"
                };
            }
        } 
        #endregion

        #region 05，分页查询+override IQueryable<BookInfo> GetPageEntities<S>(int pageSize, int pageIndex, out int total, bool isAsc, System.Linq.Expressions.Expression<Func<BookInfo, bool>> whereLambda, System.Linq.Expressions.Expression<Func<BookInfo, S>> orderByLambda)
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <typeparam name="S">排序字段</typeparam>
        /// <param name="pageSize">页大小</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="total">总条数</param>
        /// <param name="isAsc">是否倒叙</param>
        /// <param name="whereLambda">查询lambda</param>
        /// <param name="orderByLambda">排序lambda</param>
        /// <returns></returns>
        public override IQueryable<BookInfo> GetPageEntities<S>(int pageSize, int pageIndex, out int total, bool isAsc, System.Linq.Expressions.Expression<Func<BookInfo, bool>> whereLambda, System.Linq.Expressions.Expression<Func<BookInfo, S>> orderByLambda)
        {
            return DBSession.SysBookInfoRepository.GetPageEntities<S>(pageSize,pageIndex,out total,isAsc,whereLambda,orderByLambda);
        } 
        #endregion
        #region 06，新增+override bool Add(BookInfo entity)
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public override bool Add(BookInfo entity)
        {
            throw new NotImplementedException();
        } 
        #endregion

        #region 07，更新+override bool UpDate(BookInfo entity)
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public override bool UpDate(BookInfo entity)
        {
            throw new NotImplementedException();
        } 
        #endregion

        #region 08，删除+override bool Delete(BookInfo entity)
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public override bool Delete(BookInfo entity)
        {
            throw new NotImplementedException();
        } 
        #endregion
    }
}
